//
//  File.swift
//  
//
//  Created by Jiang Chencheng on 2024/9/5.
//

import Vapor
import Fluent
import struct Foundation.UUID

final class Photo: Model, @unchecked Sendable {
    
    static let schema = "photo"
    
    @ID(key: .id)
    var id: UUID?
    
    @Field(key: "url")
    var url: String
    
    @Field(key: "name")
    var name: String
    
    @Parent(key: "room_id")
    var room: Room
    
    @Timestamp(key: "created_at", on: .create)
    var createdAt: Date?

    @Timestamp(key: "updated_at", on: .update)
    var updatedAt: Date?
    
    @Timestamp(key: "deleted_at", on: .delete)
    var deletedAt: Date?
    
    init() { }
    
    init(id: UUID? = nil, name: String?, url: String) {
        self.id = id
        self.name = name ?? ""
        self.url = url
    }
    
    func toDTO() -> PhotoDTO {
        .init(
            id: self.id,
            name: self.name,
            url: self.url
        )
    }
}

